package com.aorise.controller.camera;

import com.aorise.exception.ServiceException;
import com.aorise.model.camera.*;
import com.aorise.service.camera.CameraGroupService;
import com.aorise.utils.ConstDefine;
import com.aorise.utils.StatusDefine;
import com.aorise.utils.StatusDefineMessage;
import com.aorise.utils.json.JsonResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:cat
 * @Desicription: 视频设备分组控制器类
 * @Date:Created in 2019-06-14
 * @Modified By:
 */
@RestController
@Api(description ="视频设备分组信息接口")
public class CameraGroupController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CameraGroupService cameraGroupService;

    /**
     * 查询所有视频设备分组信息（树形）
     * HTTP 方式：GET
     * API 路径：/api/cameraGroup
     * 方法名：getAllCameraGroupListTree
     * 方法返回类型：String
     *
     * @Author: cat
     * @Date: 2019-06-14
     */
    @ApiOperation(value = "查询所有视频设备分组信息（树形）", httpMethod = "GET", response = String.class, notes = "查询所有视频设备分组信息（树形）,提供所有页面查询视频设备分组下拉列表使用")
    @RequestMapping(value = "/api/cameraGroup/tree", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAllCameraGroupListTree() {
        logger.debug("Request RESTful API:getAllCameraGroupListTree");

        try {
            List<CameraGroupModel> cameraGroupModelList = cameraGroupService.getAllCameraGroupListTree();
            return new JsonResponseData(true,
                    StatusDefineMessage.GetMessage(StatusDefine.SUCCESS), StatusDefine.SUCCESS, "", cameraGroupModelList).toString();
        } catch (DataAccessException e) {
            logger.error(
                    "controller:CameraGroupController. function:getAllCameraGroupListTree...msg:Get All Camera Group List Tree DataAccessException. error:"
                            + e.getMessage());
            logger.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.DB_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.DB_ERROR), null).toString();
        } catch (Exception e) {
            logger.error(
                    "controller:CameraGroupController. function:getAllCameraGroupListTree...msg:Get All Camera Group List Tree Exception. error:"
                            + e.getMessage());
            logger.error("error:" + e.getMessage());
            return new JsonResponseData(false, "", StatusDefine.SYS_ERROR,
                    StatusDefineMessage.GetMessage(StatusDefine.SYS_ERROR), null).toString();
        }
    }

}
